package com.share.sharedevice.controller;

import com.share.common.core.domain.R;
import com.share.common.core.web.controller.BaseController;
import com.share.common.core.web.page.TableDataInfo;
import com.share.sharedevice.entity.PowerBank;
import com.share.sharedevice.service.IPowerBankService;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "充电宝接口管理")
@RestController
@RequestMapping("/powerBank")
public class PowerBankController extends BaseController {

    @Autowired
    private IPowerBankService powerBankService;

    /**
     * 获取充电宝列表
     */
    @GetMapping("/list")
    public TableDataInfo list(PowerBank powerBank){

        startPage();
        List<PowerBank> powerBankList = powerBankService.selectPowerBankList(powerBank);
        return getDataTable(powerBankList);
    }

    /**
     * 根据ID获取详细信息
     */
    @GetMapping("/{id}")
    public R<PowerBank> getPowerBankById(@PathVariable("id") Long id){
        PowerBank powerBank = powerBankService.getPowerBankById(id);
        return R.ok(powerBank);
    }

    @DeleteMapping("/{ids}")
    public R<PowerBank> delete(@PathVariable("ids") List<Long> ids){
        powerBankService.deleteByIds(ids);
        return R.ok();
    }

    /**
     * 添加
     */
    @PostMapping
    public R<PowerBank> add(@RequestBody PowerBank powerBank){
        powerBankService.add(powerBank);
        return R.ok();
    }

    /**
     * 修改
     */
    @PutMapping
    public R<PowerBank> update(@RequestBody PowerBank powerBank){
        powerBankService.updatePowerBank(powerBank);
        return R.ok();
    }

}
